{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 其他技巧",
   "id": "ecbb1fd7fc3ed42b"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-23T05:03:14.073426Z",
     "start_time": "2025-09-23T05:02:41.752779Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from selenium import  webdriver\n",
    "\n",
    "driver = webdriver.Chrome()\n",
    "driver.implicitly_wait(5)\n",
    "\n",
    "# 打开网站\n",
    "driver.get('https://www.163.com')\n",
    "\n",
    "# 获取网站标题栏文本\n",
    "print(driver.title)\n",
    "\n",
    "# 获取网站地址栏文本\n",
    "print(driver.current_url)\n",
    "\n",
    "driver.quit()"
   ],
   "id": "c0d67b6a834f09d4",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网易\n",
      "https://www.163.com/\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-23T05:04:46.729322Z",
     "start_time": "2025-09-23T05:04:27.485176Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 截屏\n",
    "from selenium import  webdriver\n",
    "driver = webdriver.Chrome()\n",
    "driver.implicitly_wait(5)\n",
    "\n",
    "driver.get('https://www.163.com')\n",
    "driver.get_screenshot_as_file('163.png')\n",
    "driver.quit()"
   ],
   "id": "3bdbfbe4eaf315b0",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-23T05:23:54.024496Z",
     "start_time": "2025-09-23T05:23:25.115429Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 以指定的手机模式打开\n",
    "\n",
    "from selenium import webdriver\n",
    "mobile_emulation = { \"deviceName\": \"iPhone 14 Pro Max\" }\n",
    "\n",
    "chrome_options = webdriver.ChromeOptions()\n",
    "chrome_options.add_experimental_option(\"mobileEmulation\", mobile_emulation)\n",
    "driver = webdriver.Chrome(options=chrome_options)\n",
    "driver.get('https://www.163.com')\n",
    "driver.quit()"
   ],
   "id": "4465abdc7e0ab583",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "ba1c65ea71842ecb"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
